package com.zretc.device.ui;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;
import java.util.List;

import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.table.DefaultTableModel;

import com.zretc.device.dao.Device_NeedDao;
import com.zretc.device.entity.Device_Need;

public class Device_needFindUserDialog1 extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JTable table;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			Device_needFindUserDialog1 dialog = new Device_needFindUserDialog1(null);
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 带参构造
	 * 
	 * @param username
	 */
	public Device_needFindUserDialog1(String username) {
		setBounds(100, 100, 899, 552);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);

		JLabel label = new JLabel("需求订单查看");
		label.setFont(new Font("宋体", Font.PLAIN, 40));
		label.setBounds(278, 28, 250, 47);
		contentPanel.add(label);

		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(33, 112, 772, 320);
		contentPanel.add(scrollPane);

		table = new JTable();
		fillTableByCode(scrollPane, username);

		// 居中
		setLocationRelativeTo(null);
	}

	/**
	 * 根据用户名设备
	 * 
	 * @param scrollPane
	 */
	private List<Device_Need> fillTableByCode(JScrollPane scrollPane, String username) {
		// 创建对象
		Device_NeedDao dnd = new Device_NeedDao();
		// 调用查找所有的方法
		List<Device_Need> list = dnd.findDevNeedByUser(username);
		if (list != null) {
			int row = list.size();
			Object[][] obj = new Object[row][8];
			// 循环遍历
			for (int i = 0; i < obj.length; i++) {
				Device_Need dn = list.get(i);
				// 赋值
				obj[i][0] = dn.getNeed_id();
				obj[i][1] = dn.getDepartment();
				obj[i][2] = dn.getDevice_code();
				obj[i][3] = dn.getNeed_num();
				obj[i][4] = dn.getBegin_date();
				obj[i][5] = dn.getEnd_date();
				obj[i][6] = dn.getNeed_person();
				obj[i][7] = dn.getNeed_tele();
			}
			table.setModel(new DefaultTableModel(obj,
					new String[] { "\u9700\u6C42\u5355\u53F7", "\u4F7F\u7528\u90E8\u95E8", "\u8BBE\u5907\u7F16\u53F7",
							"\u9700\u6C42\u6570\u91CF", "\u8D77\u6B62\u65E5\u671F", "\u7ED3\u675F\u65E5\u671F",
							"\u7533\u8BF7\u4EBA", "\u7533\u8BF7\u4EBA\u7535\u8BDD" }));
			scrollPane.setViewportView(table);
		}

		return list;
	}
}